package com.zz.parkingsystem.controller.admin;

import com.zz.parkingsystem.entity.AlipaySet;
import com.zz.parkingsystem.entity.MessageSet;
import com.zz.parkingsystem.entity.PlatformInformation;
import com.zz.parkingsystem.entity.WechatSet;
import com.zz.parkingsystem.service.PCSystemSetService;
import com.zz.parkingsystem.util.OssUtil;
import com.zz.parkingsystem.util.Result;
import com.zz.parkingsystem.util.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/system")
@Api(tags = "PC系统设置")
public class AdminSystemSetController {
    @Autowired
    private PCSystemSetService systemSetService;
    @Autowired
    private OssUtil ossUtil;//引入工具类


    @GetMapping("/queryMsgSet")
    @ApiOperation(value = "查询短信设置")
    public Result queryMessageSet() {
        MessageSet messageSetVO = systemSetService.getMessageSetByPrimaryKey();
        return ResultGenerator.genSuccessResult(messageSetVO);
    }

    @PutMapping("/updateMsgSet")
    @ApiOperation(value = "更新短信设置")
    public Result updateMessageSet(@RequestBody MessageSet messageSet) {
        String result = systemSetService.updateMessageSetByPrimaryKeySelective(messageSet);
        if("修改成功".equals(result)){
            return ResultGenerator.genSuccessResult(result);
        } else {
            return ResultGenerator.genFailResult(result);
        }
    }

    @GetMapping("/queryAliSet")
    @ApiOperation(value = "查询支付宝设置")
    public Result queryAliSet(){
        AlipaySet aliSetVO = systemSetService.getAlipaySetByPrimaryKey();
        return ResultGenerator.genSuccessResult(aliSetVO);
    }
    
    @PutMapping("/updateAliset")
    public Result updateAliset(@RequestBody AlipaySet alipaySet){
        String result = systemSetService.updateAlipaySetByPrimaryKeySelective(alipaySet);
        if("修改成功".equals(result)){
            return ResultGenerator.genSuccessResult(result);
        } else {
            return ResultGenerator.genFailResult(result);
        }
    }

    @GetMapping("/queryWechatSet")
    public Result queryWechatSet(){
        WechatSet wcSetVO = systemSetService.getWechatSetByPrimaryKey();
        return ResultGenerator.genSuccessResult(wcSetVO);
    }

    @PutMapping("/updateWechatSet")
    public Result updateWechatSet(@RequestBody WechatSet wechatSet){
        String result = systemSetService.updateWechatSetByPrimaryKeySelective(wechatSet);
        if("修改成功".equals(result)){
            return ResultGenerator.genSuccessResult(result);
        } else {
            return ResultGenerator.genFailResult(result);
        }
    }

    @GetMapping("/queryPlatInf")
    public Result queryPlatInf(){
        PlatformInformation platInfVO = systemSetService.getPlatformInformationSetByPrimaryKey();
        return ResultGenerator.genSuccessResult(platInfVO);
    }

    @PutMapping("/updatePlatInf")
    public Result updatePlatInf(@RequestBody PlatformInformation platformInformation){
        String result = systemSetService.updatePlatformInformationSetByPrimaryKeySelective(platformInformation);
        if("修改成功".equals(result)){
            return ResultGenerator.genSuccessResult(result);
        }else {
            return ResultGenerator.genFailResult(result);
        }
    }

    @ApiOperation(value = "上传图片")
    @PostMapping("/uploadoss")
    public Result fileUpload(@RequestParam("file") MultipartFile file) {
        try {
            String url = ossUtil.uploadFile(file); //调用OSS工具类
            System.out.println(url);
            return ResultGenerator.genSuccessResult(url);
        } catch (Exception e) {
            return  ResultGenerator.genFailResult("上传失败");
        }
    }

}
